<?php
/*
 * View user interface
 *
 * @version:	0.2
 * @package:	radcore
 * @update:		10 june 2010
 * @link:		http://radiance-project.com/
 * @link:		http://qfox.ru/
 * @author:		alex <alex@qfox.ru> yaroshevich
 * @copyright:	(c) 2008-2011 radiance framework
 */

class viewuser
{
	private $_user = null;
	
	public function __construct( $user )
	{
		if( !is_array( $user ) )
			$user = array( );
		
		$this ->_user = $user;
	}
	
	public function __get( $k )
	{
		if( $k == 'signed' )
			return !empty( $this ->_user );
		
		if( $k == 'somename' )
		{
			$names = array_filter( array_map( 'trim', array( $this ->fullname, $this ->nickname, $this ->login ) ) );
			return array_shift( $names );
		}
		
		if( !isset( $this ->_user[ $k ] ) )
			return null;
		
		return $this ->_user[ $k ];
	}
	
	public function __toString( )
	{
		if( empty( $this ->_user ) ) return '';
		
		return sprintf( '%s [%d]', $this ->somename, $this ->id );
	}
}
